package com.ay.jdbc.controller;

import com.ay.jdbc.mapper.OrderMapper;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * @Author: ay
 * @Date: 2021/6/30
 * @Description:
 **/
@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private OrderMapper orderMapper;

    /**
     * 保存订单信息
     * @return
     */
    @PostMapping
    public String save(){
        orderMapper.save(UUID.randomUUID().toString());
        return "ok";
    }

    /**
     * 更新订单信息
     * @param id
     * @return
     */
    @PutMapping("/{id}")
    public String update(@PathVariable Long id){
        orderMapper.update(id);
        return "ok";
    }

    /**
     * 查询订单信息
     * @return
     */
    @GetMapping
    public List<Map<String,Object>> list(@RequestParam(required = false,defaultValue = "90") Integer modulo){
        return orderMapper.list(modulo);
    }


    /**
     * 截断表
     */
    @DeleteMapping
    public String truncateTable(){
        orderMapper.truncateTable();
        return "ok";
    }

}
